import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
    state: {
			globalConfig: '',
			currentTabIndex: 0,
			userPosition: '',
			lnglat: '',
			hasLogin: false,
			userInfo: '',
            token: ''
		},
    mutations: {
			changeTab (state, provider) {
				state.currentTabIndex = provider;
			},
			setPosition(state, provider) {
				state.userPosition = provider;
				state.userPosition.lastUpdateTime = new Date().getTime();
				state.lnglat = [provider.longitude, provider.latitude]
			},
			setGlobalConfig(state, provider) {
				state.globalConfig = provider;
			},
			doLogin(state, provider) {
				state.userInfo = provider;
                state.openId = provider.openId;
				state.hasLogin = true;
			},
            commitToken(state, provider) {
				state.token = provider;
			},
			afterRz: function (state) {
				state.userInfo.rz = true;
			},
			afterGetUserProfiole: function (state, provider) {
				state.userInfo.avatar = provider.avatarUrl;
				state.userInfo.nickName = provider.nickName;
			},
			logout(state, provider) {
				state.userInfo = '';
				state.hasLogin = false;
			},
		},
    actions: {}
})
export default store